//
//  cellOneTableViewCell.m
//  spotrs
//
//  Created by xu on 16/5/16.
//  Copyright © 2016年 TZ. All rights reserved.
//

#import "cellOneTableViewCell.h"
#import "MyobligationCtrl.h"
#import "MyOffCtrl.h"
#import "MyPaidCtrl.h"
#import "MyEvaluateCtrl.h"
@implementation cellOneTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier count:(int)count
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _count = count;
        [self creatView];
    }
    return  self;
}
-(void)creatView
{
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(15, 7, 20,20 )];
    [self setBackgroundColor:[UIColor redColor]];
    [self addSubview:image1];
    
    UILabel *dingdan = [[UILabel alloc] initWithFrame:CGRectMake(38, 7, 80, 20)];
    [dingdan setText:@"我的订单"];
    [dingdan setFont:[UIFont systemFontOfSize:13]];
    [self addSubview:dingdan];
    
    [self addSubview:[[helpUser sharedInstance] creatLineLabel:[UIColor grayColor] frem:CGRectMake(0, 32, SCREEN_WIDTH, 1)]];
    
    for (int i = 0; i < _count ; i++)
    {
        [self fenLeiIcon:i name:@"待付款"];
    }
    [self addSubview:[[helpUser sharedInstance] creatLineLabel:[UIColor grayColor] frem:CGRectMake(0, 121, SCREEN_WIDTH, 1)]];
}
-(void)fenLeiIcon:(int)number name:(NSString*)name
{
    float EdgeInsets = (SCREEN_WIDTH-50*_count)/_count+1;
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(EdgeInsets/2+(number *(50+EdgeInsets)),37, 50, 85)];
    [self addSubview:backView];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [image setBackgroundColor:[UIColor redColor]];
    [backView addSubview:image];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 50, 30)];
    [label setText:name];
    [label setFont:[UIFont systemFontOfSize:12]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [backView addSubview:label];
    
    UIButton  * tap = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 85)];
    [tap addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [tap setTag:(number +1)*1000];
    [backView addSubview:tap];
}
-(void)btnClick:(UIButton*)sender
{
    if (_count == 4) {
        switch (sender.tag ) {
            case 1000:
            {
                NSLog(@"1");
                MyobligationCtrl *myobilg = [[MyobligationCtrl alloc]init];
                [theApp pushController:myobilg];
            }
                break;
            case 2000:
            {
                MyPaidCtrl *paid = [[MyPaidCtrl alloc]init];
                [theApp pushController:paid];
            }
                break;
            case 3000:
            {
                NSLog(@"3");
                MyEvaluateCtrl *myeva = [[MyEvaluateCtrl alloc]init];
                [theApp pushController:myeva];
            }
                break;
            case 4000:
            {
                NSLog(@"4");
                MyOffCtrl *myoff = [[MyOffCtrl alloc]init];
                [theApp pushController:myoff];
            }
                break;
                
            default:
                break;
        }
    }
    else
    {
        switch (sender.tag ) {
            case 1000:
            {
                NSLog(@"1");
            }
                break;
            case 2000:
            {
                NSLog(@"2");
            }
                break;
            case 3000:
            {
                NSLog(@"3");
            }
                break;
                
            default:
                break;
        }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
